package com.mhuang.module.wechat.controller;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mhuang.module.common.controller.BaseController;
import com.mhuang.module.wechat.service.WechatConfigService;
import com.mhuang.module.wechat.service.WechatService;

/**
 * 微信控制层 
 * @author mHuang
 *
 */
@Controller
@RequestMapping("/wechat")
public class WechatController extends BaseController{

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private WechatService wechatService;
	
	@ResponseBody
	@RequestMapping("callBack")
	public String callBack(HttpServletRequest request){
		boolean isGetMethod = request.getMethod().toLowerCase().equals("get");
		if(isGetMethod){
			return request(request,"echostr");
		}else{
			String responseString =  wechatService.callback(parseXml(request));
			logger.debug("返回给微信的参数："+responseString);
			return responseString;
		}
	}
	
}
